package com.suneee.base.util;


import sun.misc.BASE64Decoder;
import sun.misc.BASE64Encoder;

public class EmailUrlUtil {
	private static int index = 4;
	public static String encrypt(String str) {
		String ss = null;
		try {
			String data = (new BASE64Encoder()).encodeBuffer(str.getBytes());
			data = data.replaceAll("[\\s*\\t\\n\\r]", "");
			StringBuffer sb = new StringBuffer();
			String reStr = sb.append(data).reverse().toString();
			String sub1 = reStr.substring(0, index);
			String sub2 = reStr.substring(index);
			ss = sub2 + new StringBuffer(sub1).reverse().toString();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ss;
	}

	/**
	 * 解密
	 * 
	 * @param str
	 * @return
	 * @throws Exception
	 */
	public static String decrypt(String str) {
		String ss = null;
		try {
			String sub1 = str.substring(0, str.length() - index);
			String sub2 = str.substring(str.length() - index);
			String s = new StringBuffer(sub2).reverse().toString() + sub1;
			s = new StringBuffer(s).reverse().toString();
			ss = new String((new BASE64Decoder()).decodeBuffer(s));
		} catch (Exception e) {
			e.printStackTrace();
		}
		return ss;
	}
	
	public static void main(String[] args){
		System.out.println(EmailUrlUtil.encrypt("13"));
		System.out.println(EmailUrlUtil.decrypt("wYjN3UjN4MTMNjc="));
		//" htpp://localhost:8088/suneee-cloud/services"
	}
}
